/**
 * 数据转换辅助函数测试
 * 用于验证日期和状态处理辅助函数
 */

// 引入项目辅助函数配置
const { dateHelper, statusHelper } = require('../config/project_helpers_config');

// 测试样例项目数据
const sampleProject = {
  _id: 'proj_123456',
  model: 'ABS-2023-001',
  projectType: '霍尔',
  customerName: 'ABS电机公司',
  description: '测试项目描述',
  priority: 'normal',
  startDate: 1672531200, // 2023-01-01
  deadline: 1704067200,  // 2024-01-01
  level1: 3,             // 活动状态
  level2: 'development', // 开发阶段
  level3: 'firmware_development', // 固件开发
  completionPercentage: 60,
  developmentManager: '张工',
  businessManager: '李经理'
};

// 测试日期辅助函数
function testDateHelper() {
  console.log('=== 测试日期辅助函数 ===');
  
  // 测试dateToTimestamp
  console.log('dateToTimestamp:');
  console.log('空值:', dateHelper.dateToTimestamp(null));
  console.log('已有时间戳:', dateHelper.dateToTimestamp(1672531200));
  console.log('日期字符串:', dateHelper.dateToTimestamp('2023-01-01'));
  
  // 测试timestampToDate
  console.log('\ntimestampToDate:');
  console.log('空值:', dateHelper.timestampToDate(null));
  console.log('时间戳(默认格式):', dateHelper.timestampToDate(1672531200));
  console.log('时间戳(自定义格式):', dateHelper.timestampToDate(1672531200, 'YYYY年MM月DD日'));
  
  // 测试daysBetween
  console.log('\ndaysBetween:');
  console.log('与当前日期差:', dateHelper.daysBetween(1672531200));
  console.log('两个时间戳差:', dateHelper.daysBetween(1672531200, 1704067200));
  
  // 测试getWeekday
  console.log('\ngetWeekday:');
  console.log('星期几:', dateHelper.getWeekday(1672531200));
  
  // 测试getDeadlineStatus
  console.log('\ngetDeadlineStatus:');
  console.log('截止状态:', dateHelper.getDeadlineStatus(1704067200));
  
  // 测试getProgressColor
  console.log('\ngetProgressColor:');
  console.log('进度颜色(基于完成百分比):', dateHelper.getProgressColor(null, null, 60));
  console.log('进度颜色(基于时间):', dateHelper.getProgressColor(1672531200, 1704067200));
}

// 测试状态辅助函数
function testStatusHelper() {
  console.log('\n=== 测试状态辅助函数 ===');
  
  // 测试getStatusText
  console.log('getStatusText:');
  console.log('状态文本:', statusHelper.getStatusText(sampleProject.level1, sampleProject.level2));
  
  // 测试getFullStatusDesc
  console.log('\ngetFullStatusDesc:');
  console.log('完整状态描述:', statusHelper.getFullStatusDesc(sampleProject));
  
  // 测试getDevelopmentStatus
  console.log('\ngetDevelopmentStatus:');
  console.log('开发状态:', statusHelper.getDevelopmentStatus(sampleProject));
  
  // 测试getStatusColor
  console.log('\ngetStatusColor:');
  console.log('状态颜色:', statusHelper.getStatusColor(sampleProject));
  
  // 测试getCompletionPercentage
  console.log('\ngetCompletionPercentage:');
  console.log('带有完成度的项目:', statusHelper.getCompletionPercentage(sampleProject));
  console.log('无完成度的项目:', statusHelper.getCompletionPercentage({
    level1: 3,
    level2: 'development'
  }));
  
  // 测试canTransition
  console.log('\ncanTransition:');
  const currentStatus = { level1: 3, level2: 'development' };
  const targetStatus = { level1: 3, level2: 'testing' };
  console.log('状态流转验证:', statusHelper.canTransition(currentStatus, targetStatus));
  
  // 测试getNextStatusOptions
  console.log('\ngetNextStatusOptions:');
  console.log('下一步状态选项:', statusHelper.getNextStatusOptions(sampleProject));
}

// 执行测试
function runTests() {
  console.log('开始测试数据转换辅助函数...\n');
  
  try {
    // 测试日期辅助函数
    testDateHelper();
    
    // 测试状态辅助函数
    testStatusHelper();
    
    console.log('\n测试完成!');
  } catch (error) {
    console.error('\n测试过程中发生错误:', error);
  }
}

// 运行测试
runTests(); 